from etx import db, ma
from config import configdev as dev
from flask_cors import CORS
from flask_migrate import Migrate
from config.responseconfig import JSONResponse
from flask import Flask
import click
from controller.usercontroller import user_bp

app = Flask(__name__)
app.config.from_object(dev)
db.init_app(app)
ma.init_app(app)
# 配置数据库迁移  将ORM模型映射到数据库中
# flask db init 初始化迁移仓库
# flask db migrate 生成迁移脚本
# flask db upgrade 运行迁移脚本
migrate = Migrate(app, db)
# 设置支持跨域
CORS(app, supports_credentials=True)
# 配置json回参格式
app.response_class = JSONResponse

# 注册蓝图
app.register_blueprint(user_bp)


@click.command()
@click.option("--port", default=8081)
@click.option("--host", default="0.0.0.0", type=str)
@click.option("--debug", default=True, type=bool)  # 开发环境下开启
def run(port, host, debug):
    app.run(port=port, host=host, debug=debug)


if __name__ == '__main__':
    run()
